/*
 * This class was automatically generated with 
 * <a href="http://www.castor.org">Castor 1.3</a>, using an XML
 * Schema.
 * $Id$
 */
package nl.biggrid.plier.opm;

import java.util.Iterator;
import java.util.LinkedHashSet;
import nl.biggrid.plier.event.Event;

import javax.jdo.annotations.PersistenceCapable;
/**
 * This class represents a OPM graph (i.e a set of artifacts,
 * processes, agents, edges, and accounts along with the causal 
 * dependencies). It is a set of assertions about the provenance
 * of things.
 * 
 * @version $Revision$ $Date$
 */
@SuppressWarnings("serial")
@PersistenceCapable
public class OPMGraph implements java.io.Serializable {


    //--------------------------/
    //- Class/Member Variables -/
    //--------------------------/

    /**
     * Field id.
     */
    private String id;
    /**
     * Field desc.
     */
    private String desc;
    /**
     * Field accounts.
     */
    private LinkedHashSet<Account> accounts;
    /**
     * Field processes.
     */
    private LinkedHashSet<Process> processes;
    /**
     * Field artifacts.
     */
    private LinkedHashSet<Artifact> artifacts;
    /**
     * Field agents.
     */
    private LinkedHashSet<Agent> agents;
    /**
     * Field _causalDependencies.
     */
    private LinkedHashSet<Dependency> dependencies;
    /**
     * Field events.
     */
    private LinkedHashSet<Event> events;

    /**
     * Field timestamp for Castor to be able to update persistent OPMGraph objects.
     */
    //private long timestamp;
    //----------------/
    //- Constructors -/
    //----------------/
    /**
     * Class constructor.
     */
    public OPMGraph() {
        super();

        accounts = new LinkedHashSet<Account>();
        processes = new LinkedHashSet<Process>();
        artifacts = new LinkedHashSet<Artifact>();
        agents = new LinkedHashSet<Agent>();
        dependencies = new LinkedHashSet<Dependency>();
        events = new LinkedHashSet<Event>();
    }


    //-----------/
    //- Methods -/
    //-----------/

    /**
     * Returns the OPM ID of this graph.
     *
     * @return the OPM ID of this graph.
     */
    public String getId() {
        return this.id;
    }

    /**
     * Returns the list of accounts in this graph as an Accounts object.
     * 
     * @return An Accounts object representing the list of accounts in this graph.
     */
    public LinkedHashSet<Account> getAccounts() {
        return this.accounts;
    }

    /**
     * Returns the list of agents in this graph as an Agents object.
     *
     * @return An Agents object representing the list of agents in this graph.
     */
    public LinkedHashSet<Agent> getAgents() {
        return this.agents;
    }

    /**
     * Returns the list of artifacts in this graph as an Artifacts object.
     *
     * @return An Artifacts object representing the list of artifacts in this graph.
     */
    public LinkedHashSet<Artifact> getArtifacts() {
        return this.artifacts;
    }


    /**
     * Returns the list of causal dependencies in this graph as a CausalDependencies object.
     *
     * @return A CausalDependencies object representing the list of artifacts in this graph.
     */
    public LinkedHashSet<Dependency> getDependencies() {
        return this.dependencies;
    }

    /**
     * Returns the graph description.
     * 
     * @return A string representing the graph description.
     */
    public String getDescription() {
        return this.desc;
    }

    /**
     * Returns the list of processes in this graph as a Processes object.
     * 
     * @return A Processes object representing the list of processes in this graph.
     */
    public LinkedHashSet<Process> getProcesses() {
        return this.processes;
    }

    /**
     * Returns the list of events in this graph as an Events object.
     *
     * @return An Events object representing the list of events in this graph.
     */
    public LinkedHashSet<Event> getEvents() {
        return this.events;
    }

    /**
     * Sets the OPM ID of this graph.
     *
     * @param id the value of the OPM ID.
     */
    public void setId(
            final String id) {
        this.id = id;
    }

    /**
     * Sets the list of accounts in this graph from an Accounts object.
     * 
     * @param accounts The Accounts object to set the list of accounts from.
     */
    public void setAccounts(
            final LinkedHashSet<Account> accounts) {
        this.accounts = accounts;
    }

    /**
     * Sets the list of agents in this graph from an Agents object.
     *
     * @param agents The Agents object to set the list of agents from.
     */
    public void setAgents(
            final LinkedHashSet<Agent> agents) {
        this.agents = agents;
    }

    /**
     * Sets the list of artifacts in this graph from an Artifacts object.
     *
     * @param artifacts The Artifacts object to set the list of artifacts from.
     */
    public void setArtifacts(
            final LinkedHashSet<Artifact> artifacts) {
        this.artifacts = artifacts;
    }

    /**
     * Sets the list of causal dependencies in this graph from an CausalDependencies object.
     *
     * @param causalDependencies The CausalDependencies object to set the list of causal dependencies from.
     */
    public void setDependencies(
            final LinkedHashSet<Dependency> Dependencies) {
        this.dependencies = Dependencies;
    }

    /**
     * Sets the description of this graph.
     * 
     * @param description the description content.
     */
    public void setDescription(
            final String description) {
        this.desc = description;
    }

    /**
     * Sets the list of processes in this graph from an Processes object.
     *
     * @param processes The Processes object to set the list of processes from.
     */
    public void setProcesses(
            final LinkedHashSet<Process> processes) {
        this.processes = processes;
    }

    /**
     * Sets the list of events in this graph from an Events object.
     *
     * @param events The Events object to set the list of events from.
     */
    public void setEvents(
            final LinkedHashSet<Event> events) {
        this.events = events;
    }

    /**
     * Sets the OPM Graph ready for storage. For object-relational mapping to work
     * properly, we need to establish to which graph all persistent OPM entities
     * belong to.
     *
     */
    public void SetInverseRelations() {
        java.util.LinkedHashSet<Process> vProcess = this.getProcesses();
        Iterator<Process> procItor = vProcess.iterator();
        while (procItor.hasNext()) {
            Process data = procItor.next();
            data.setGraph(this);
        }

        java.util.LinkedHashSet<Artifact> vArtifact = this.getArtifacts();
        Iterator<Artifact> artItor = vArtifact.iterator();
        while (artItor.hasNext()) {
            Artifact data = (Artifact) artItor.next();
            data.setGraph(this);
        }

        java.util.LinkedHashSet<Agent> vAgent = this.getAgents();
        Iterator<Agent> agnItor = vAgent.iterator();
        while (agnItor.hasNext()) {
            Agent data = agnItor.next();
            data.setGraph(this);
        }

        java.util.LinkedHashSet<Account> vAccount = this.getAccounts();
        Iterator<Account> accItor = vAccount.iterator();
        while (accItor.hasNext()) {
            Account data = (Account) accItor.next();
            data.setGraph(this);
        }

        java.util.LinkedHashSet<Dependency> vCausalDependency = this.getDependencies();
        Iterator<Dependency> depItor = vCausalDependency.iterator();
        while (depItor.hasNext()) {
            Dependency data = depItor.next();
            data.setGraph(this);
        }

        java.util.LinkedHashSet<Event> vEvent = this.getEvents();
        Iterator<Event> evtItor = vEvent.iterator();
        while (evtItor.hasNext()) {
            Event data = evtItor.next();
            data.setGraph(this);
        }
    }
}
